﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using BLL;

namespace TaoBaoProject.Handlers.UserHandler
{
  /// <summary>
  /// Summary description for GetPasswordByUserName
  /// </summary>
  public class GetPasswordByUserName : IHttpHandler
  {

    public void ProcessRequest(HttpContext context)
    {
      context.Response.ContentType = "text/plain";
      string username = context.Request.Params["username"];
      string password = context.Request.Params["password"];
      string proid = context.Request.Params["id"].ToString();
      UserBLL userBll = new UserBLL();
      try
      {
        DataTable users = UserBLL.GetUserByName(username);
        if (users.Rows.Count > 0)
        {
          string temp = Convert.ToString(users.Rows[0]["Password"]);
          if (temp == password)
          {
            if (RegisterBLL.DeleteRegister(proid) == 1)
            {
              context.Response.Write("success");
              return;
            }
          }
          else
          {
            context.Response.Write("{fail:'false'}");
          }
        }
      }
      catch (Exception ex)
      {
        context.Response.Write("{'exception':未知异常}");
      }
    }

    public bool IsReusable
    {
      get
      {
        return false;
      }
    }
  }
}